# -*- coding: utf-8 -*-
"""
Created on Wed Jan 22 16:36:44 2020

@authors: enrijeta shino
@department: political science 
@institution: university of alabama
"""

## Import modules 
import os 
import numpy as np 
import matplotlib.pyplot as plt
import pandas as pd 
import csv

import matplotlib.ticker as mtick


# =============================================================================
# ================================ FIGURE TIMELINE ============================
# =============================================================================


# import the data
graph_data = pd.read_csv('/Users/enrijetashino/Desktop/timeline_interest.csv')
graph_data = pd.DataFrame(graph_data)

## set 'Date' variable as index 
graph_data = graph_data.set_index('Date')


# start the figure and axis 
fig, ax = plt.subplots(figsize=(22,14))

# plot the each series 
ax.plot(graph_data.index, graph_data['Absentee ballot'], '--', color='#A780FF', 
        label="Absentee ballot", linewidth=4)

ax.plot(graph_data.index, graph_data['Vote by mail'], '-.', color='#472695', 
        label="Vote by mail", linewidth=4)


# set upper and lower value of y 
ax.set_ylim([0, 100])

# Size of the tikz labels 
ax.tick_params(axis="y", labelsize=30, width=2.5)

ax.tick_params(axis='x', which='both', width=0, labelsize=20)

# rotate the labels of the first x-axis to 45 degrees 
ax.set_xticks(ax.get_xticks()[::2])
ax.tick_params(axis='x', rotation=45)

# set the  title of the figure, xlabel and ylabel 
ax.set_ylabel('Interest over time', fontsize=35, labelpad=15)

# set the shaded area that denotes our period of survey 
ax.axvspan(47, 49, facecolor='#D3D3D3', alpha=0.5)


# set the visibility of the spines top and right to false 
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

# set the width of the axis
for axis in ['left','bottom']:
  ax.spines[axis].set_linewidth(2)
  

# specify the location of the legend, remove its frame, and set its size 
ax.legend(loc='upper left', bbox_to_anchor=(0.02,0.95), prop={"size":30}, 
          fancybox = True)

# save figure
fig.savefig('/Users/enrijetashino/Desktop/timeline_graph.png', dpi=100, bbox_inches='tight')